package com.joycessh.service.impl;

import com.joycessh.dao.SeedUrlMapper;
import com.joycessh.domain.crawl.SeedUrl;
import com.joycessh.service.SeedUrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Joycessh
 * @Description
 * @Date 5/9/19 4:18 PM
 */
@Service
public class SeedUrlServiceImpl implements SeedUrlService {

    @Autowired
    private SeedUrlMapper seedUrlMapper;

    @Override
    public boolean save(SeedUrl seedUrl) {
        return seedUrlMapper.insertSelective(seedUrl) == 1 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public boolean delete(Integer seedUrlId) {
        return seedUrlMapper.deleteByPrimaryKey(seedUrlId) == 1 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public boolean update(SeedUrl seedUrl) {
        return seedUrlMapper.updateByPrimaryKeySelective(seedUrl) == 1 ? Boolean.TRUE : Boolean.FALSE;
    }

    @Override
    public List<SeedUrl> findAll(Integer seedListId) {
        List<SeedUrl> lists = new ArrayList<>();
        try {
            lists = seedUrlMapper.selectBySeedListId(seedListId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return lists;
    }
}
